package com.guochenglang.www.util.connect;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Connectpool的实现类，避免暴露底层
 *
 * @author 郭程朗
 */
public class ConnectManager implements Connectutil {
    private static final ConnectManager CONNECT_MANAGER = new ConnectManager();
    /**
     * 创建连接池对象
     */
    private static final ConnectPool POOL = new ConnectPool();

    /**
     * 私有化构造方法,不让外部多次创建对象
     */
    private ConnectManager() {
    }

    /**
     * 获得唯一的连接池对象
     */
    public static ConnectManager getPool() {
        return CONNECT_MANAGER;
    }

    /**
     * 获取连接
     */

    @Override
    public Connection getConnection() throws InterruptedException, SQLException {
        return POOL.getConnection();
    }

    /**
     * 归还连接
     */
    @Override
    public void returnConnection() throws SQLException {
        POOL.returnConnection();
    }

    /**
     * 释放连接
     */
    @Override
    public void releaseConnection() {
        POOL.releaseConnection();
    }

    /**
     * 释放全部资源
     *
     * @param conn      Connection连接
     * @param state     Statement连接
     * @param resultSet Resultset连接
     */
    @Override
    public void releaseAll(Connection conn, Statement state, ResultSet resultSet) {
        POOL.releaseAll(conn, state, resultSet);
    }


}
